<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		//var messageNo;
		$("#messageListBySender").hide();
		//$("#messageListBySender").on(":input[name=senderBtn]","click",function(){
			
		
		$(":input[name=senderBtn]").click(function(){
			
			$("#messageListBySender").toggle(1000);
			
				$.ajax({
				type:"get",
				url:"${initParam.root}member/getMessageBySender.moja",
				
				success:function(jsonData){
					if(jsonData==""){
						alert("보낸 쪽지가 없습니다.");
					}else{
						var senderList="<table border=2 cellpadding=5><tr><td>받은사람</td><td>제목</td><td>내용</td></tr>";
						$.each(jsonData,function(index,data){
							senderList+="<tr><td>";
							senderList+=data.memberId+"</td><td>"+data.messageTitle+"</td><td>"+data.messageContent+"</td><td>"+"<a href=${initParam.root }member/deleteSender.moja?messageNo="+data.messageNo+"><input type=button name=senderdeleteBtn value=삭제></a>";
							//senderList+=data.memberId+"</td><td>"+data.messageTitle+"</td><td>"+data.messageContent+"</td><td><input type=button name=deleteBtn value=삭제>";
							senderList+="</td></tr>";
							messageNo=data.messageNo;
						});
						senderList+="</table>";
						$("#messageListBySender").html(senderList);
					}
					
				}
			});
			
		});//click
		
		
	
		
		//sender
/* ===============================================================	 */		
	  // receiver
 $("#messageListByReceiver").hide();
 $(":input[name=receiverBtn]").click(function(){
			//alert("aaa");
			$("#messageListByReceiver").toggle(1000);
			
				$.ajax({
				type:"get",
				url:"${initParam.root}member/getMessageByReceiver.moja",
				
				success:function(jsonData){
					if(jsonData==""){
						alert("받은 쪽지가 없습니다.");
					}else{
						var receiverList="<table border=2 cellpadding=5><tr><td>보낸사람</td><td>제목</td><td>내용</td></tr>";
						$.each(jsonData,function(index,data){
							receiverList+="<tr><td>";
							receiverList+=data.sender+"</td><td>"+data.messageTitle+"</td><td>"+data.messageContent+"</td><td>"+"<a href=${initParam.root }member/deleteRecevier.moja?messageNo="+data.messageNo+"><input type=button name=recevierdeleteBtn value=삭제></a>";
							receiverList+="</td></tr>";
						});
						receiverList+="</table>";
						$("#messageListByReceiver").html(receiverList);
					}
					
				}
			});
		});	
		
	});
</script>
<div id="mainCss">
	
	<input type="button" name="senderBtn" value="보낸 쪽지함">
		
		<div id="messageListBySender"></div>
		
		<input type="button" name="receiverBtn" value="받은 쪽지함">
		
		<div id="messageListByReceiver"></div> 
		<hr>
		<a href="${initParam.root }member/home.moja">home으로 가용!!!</a>
		
</div>
